package com.renu.jdependencyanalyser.window.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.renu.jdependencyanalyser.cons.ProjectCons;
import com.renu.jdependencyanalyser.core.JarBorderGene;
import com.renu.jdependencyanalyser.core.ProjectInfo;
import com.renu.jdependencyanalyser.data.ProjectDataCenter;
import com.renu.jdependencyanalyser.freemarker.DependencyProcessor;
import com.renu.jdependencyanalyser.freemarker.JarDependencyProcessor;
import com.renu.jdependencyanalyser.utils.MyFileUtil;
import com.renu.jdependencyanalyser.utils.MyProjectUtil;
import com.renu.jdependencyanalyser.visualizer.GraphvizVisualizer;
import com.renu.jdependencyanalyser.window.AnalyserWindow;
import com.renu.jdependencyanalyser.utils.ImageDialogUtil;
import com.renu.jdependencyanalyser.window.PanelShow;

import java.io.File;
import java.util.logging.Logger;

public class DpndcyJarAction extends AnAction {

    private static final Logger logger = Logger.getLogger(DpndcyJarAction.class.getName());

    ProjectInfo projectInfo ;

    JarBorderGene jarBorderGene = null;
    private DependencyProcessor jarDependencyProcessor = null;
    private AnalyserWindow analyserWindow;


    @Override
    public void actionPerformed(AnActionEvent e) {
        projectInfo = ProjectDataCenter.projectInfo;
        if ( MyProjectUtil.projectBasePath==null)
            return;
        logger.info("==================DpndcyJar begins=================");
        MyFileUtil.createOutDir(MyProjectUtil.projectBasePath + ProjectCons.OUT_DIR);
       jarBorderGene = new JarBorderGene(projectInfo);
       //jarDependencyProcessor = new JarDependencyProcessor(jarBorderGene);
        jarDependencyProcessor = new DependencyProcessor(jarBorderGene);
        String filePath  = MyProjectUtil.projectBasePath + ProjectCons.OUT_DIR+ File.separator + MyProjectUtil.getProjectName() +".png" ;
        GraphvizVisualizer graphvizVisualizer = new GraphvizVisualizer();
        graphvizVisualizer.generateGraph(jarDependencyProcessor,
                filePath);

        ImageDialogUtil.showImage(filePath,"查看第三方库依赖图");
        analyserWindow = ProjectDataCenter.analyserWindow;
         PanelShow panelShow = new PanelShow(projectInfo);
        panelShow.initOuterLib(analyserWindow.getTb_outerLib(),analyserWindow.getTxt_outerLib());


        logger.info("==================DpndcyJar done=================");
    }
}
